<!--
 * @Description: file content
 * @Author: Wenmin He
 * @Date: 2021-07-02 17:25:17
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-07-31 19:09:27
-->
<template>
  <view class="successful" :style="{ marginTop: barHeight }">
    <top-bar
      :title="'已完成'"
      :bgColor="'#ffffff'"
      :titleColor="'#000000'"
      @btnClick="returnPage"
    >
    </top-bar>
    <view class="img-content">
      <img
        class="img-box"
        src="https://szgd-dev.tgovcloud.com/public/images/suc.png"
        alt=""
      />
      <view class="text-content">
        <view>已完成</view>
        <view>隔离延期</view>
      </view>
    </view>

    <!-- <view class="userInfo" v-if="!checkouted">
      <view class="userItem">
        <view class="userLeft">登记时间</view>
        <view class="userRight"><span class="curYear">{{date}}</span></view>
      </view>
      <view class="userItem">
        <view class="userLeft">登记人员</view>
        <view class="userRight">{{userInfo.name}}</view>
      </view>
    </view> -->

    <view class="button-gob" v-if="isChange == '1'">
      <view class="gob button default" @click="goback">返回</view>
    </view>
    <view class="button-wrapper" v-else>
      
      <view class="button modify" @click="nextBtn">{{ isSelectRoom ? "" : "扫描" }}下一个</view
      >
      <view class="button default"  @click="leftClick">{{ leftButton }}</view>
    </view>
  </view>
</template>

<script>
import { scanCode } from "@/utils";
import TopBar from "../../../components/TopBar.vue";
import dayjs from "dayjs";
export default {
  components: {
    TopBar,
  },
  data() {
    return {
      isChange: '0',
      title: "",
      leftButton: "",
      type: "",
      barHeight: "",
      isSelectRoom: "",
      userInfo:{},
      date: dayjs().format('YYYY-MM-DD HH:mm:ss'),
    };
  },
  onLoad(options) {
    this.geAdmin();
    this.isChange = options.isChange;
    let { isSelectRoom } = this.$store.state;
    this.isSelectRoom = isSelectRoom;
    // this.title = options.title === "health" ? "健康评估登记" : "心理综合评估";
    this.leftButton = isSelectRoom ? "选择其他房间" : "回到首页";
    //设置marginTop
    uni.getSystemInfo({
      success: (res) => {
        this.barHeight = `${res.statusBarHeight}px`;
      },
    });
  },

  methods: {
    // goback() {
    //   uni.navigateBack({
    //     delta: 5,
    //   });
    // },

    //获取当前管理员身份
    geAdmin () {
      this.userInfo = uni.getStorageSync("personalInfo");
    },
    nextBtn() {
      if (this.isSelectRoom) {
        this.nextOne();
      } else {
        this.nextPart();
      }
      this.$store.commit('REMOVE_DATA_IGP')
    },
    //健康评估 下一个
    nextOne() {
      // 如果是选房流程。 判断还有没有人 ，有人就下一个，没人就回房间
      this.$store.commit("FINISH_CHECK");
      if (this.$store.state.personDetail.length !== 0) {
        let nextOne = this.$store.state.personDetail[0];
        this.$store.commit("PERSON_ID", [nextOne.personId]);
        uni.setStorage({ key: "personInfo", data: nextOne });
        uni.reLaunch({
          url: "../IsolationDelay/index?type=IsolationDelay",
        });
      } else {
        //根据type判断是扫码进入还是房间进入
        uni.showToast({
          title: "该房间已评估完",
          duration: 2000,
          icon: "none",
          success: () => {},
        });
        uni.reLaunch({
          url: "../../../pages/publicRooms/index?type=IsolationDelay",
        });
      }
    },
    // 扫描下一个
    nextPart() {
      let that = this;
      scanCode({
        fn: function (data) {
          let personState = data.targetUser.personInfo.personState;
          if (personState == 12 || personState == 21 || personState == 22) {
            // 待入住、已入住
            uni.reLaunch({
              url: "../referral/index",
            });
          } else {
            //未入住
            that.$store.commit("SET_IS_SELECT_ROOM", false);
            uni.navigateTo({
              url: `/packageIsolate/pages/userBaseInfo/index?addPerson=true`,
            });
            return;
            // uni.showToast({
            //   title: `人员未入住，无法进行此操作！`,
            //   icon: 'none',
            //   duration: 3000
            // });
          }
        },
      });
    },
    leftClick() {
      if (this.isSelectRoom) {
        this.$store.commit("PERSON_DETAIL", []);
        uni.reLaunch({
          url: "../../../pages/publicRooms/index?type=IsolationDelay",
        });
      } else {
        uni.switchTab({
          url: `../../../pages/index/index`,
        });
      }
    },
    //右上角返回首页
    returnPage() {
      this.$store.commit("PERSON_DETAIL", []);
      uni.switchTab({
        url: `../../../pages/index/index`,
      });
    },
  },
};
</script>

<style scoped lang="scss">
.successful {
  background: #f9f9f9;
  // padding-top: 76rpx;
  .img-content {
    height: 638rpx;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #fff;
    img {
      width: 178rpx;
      height: 226rpx;
    }
    .img-box {
      margin-top: 160rpx;
    }
    .text-content {
      text-align: center;
      font-size: 40rpx;
      font-weight: bold;
      line-height: 60rpx;
      color: #333;
      margin-top: 56rpx;
    }
  }
  .button-wrapper {
    // display: flex;
    // justify-content: space-between;
    padding: 0 32rpx;
    margin-top: 50rpx;
  }
  
  .button-gob {
    padding-top: 40rpx;
    background-color: #fff;
  }
  .button {
    width: 100%;
    height: 94rpx;
    background: #ffffff;
    border: 1rpx solid #2c9af1;
    opacity: 1;
    border-radius: 16rpx;
    text-align: center;
    line-height: 94rpx;
    margin-bottom: 30rpx;
    font-size: 34rpx;
    &.gob {
      margin: 0 auto;
    }
    &.default {
      color: #2c9af1;
    }
    &.modify {
      color: #fff;
      background: rgba(44, 154, 241, 1);
    }
    &.primary {
      color: #fff;
      background: #2c9af1;
      border-color: #2c9af1;
    }
  }
}
.userInfo{
  background-color: #ffffff;
  margin-top: 32rpx;
  .userItem{
    display: flex;
    height: 96rpx;
    line-height: 96rpx;
    box-sizing: border-box;
    padding: 0 32rpx;
    .userLeft{
      color: #999999;
      text-align: left;
      font-size: 30rpx;
    }
    .userRight{
      flex: 1;
      color: #666666;
      text-align: right;
      font-size: 34rpx;
    }
  }
}
</style>
